$(function(){
	//1.0绑定表格
	var datagrid;
	var editRow = undefined;
	var newArr=[
                {field: 'name', title: '参数 ', width: 100},
                {field: 'description', title: '描述 ', width: 100,editor:{type:"validatebox"}},
                {field: 'type', title: '类型选择', width: 100,editor:{type:"validatebox",options: { required: true}}},
                {field: 'value', title: '默认值 ', width: 80,editor:{type:"validatebox",options: { required: true}}}
            ];
	datagrid=$("#updateDatagrid").datagrid({
		columns: [newArr],
		singleSelect:true,
		onAfterEdit: function (rowIndex, rowData, changes) {
            //endEdit该方法触发此事件
            console.info(rowData);
            editRow = undefined;
        },
        onDblClickRow: function (rowIndex, rowData) {
        //双击开启编辑行
            if (editRow != undefined) {
                datagrid.datagrid("endEdit", editRow);
            }
            if (editRow == undefined) {
                datagrid.datagrid("beginEdit", rowIndex);
                editRow = rowIndex;//给editRow对象赋值，index为当前行的索引
            }
        }
        });
	//2.0绑定数据
	var formId=$("#formId").val();
	$.post(contextpath+"/report/form/getForm",{
		formId:formId
	},function(jsObj){
		//2.1绑定表单
		console.log(jsObj);
		$("input[name='name']").val(jsObj.name);
		$("#hsql").html(jsObj.hsql);
		$("#description").html(jsObj.description);
		//2.2绑定表格数据
		datagrid.datagrid("loadData",jsObj.paramList);
	},"json");

	$("#hsql").change(function(){
		var content=$(this).val();
			var re = /:.*?:/g;
			var arr = content.match(re);
			console.log(arr);
			if(arr){
				//清除所有行
				datagrid.datagrid('loadData', { total: 0, rows: [] });//清空下方DateGrid 
				$.each(arr,function(i,v){
					var field=v.replace(":","").replace(":","");
					datagrid.datagrid('insertRow',{
						row:{
							id:'',
						name: field,
						description: '',
						type: '',
						display:''
						}
					});
				
				});
			}
	});
});